import axios from "axios";
import type { AxiosInstance } from "axios";
import { message } from "ant-design-vue";
const service: AxiosInstance = axios.create({
  //配置的跨域标识
  baseURL: import.meta.env.VITE_APP_BASE_API,
  //请求头
  headers: {},
  //超时
  timeout: 10000,
});
//请求拦截器
service.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    console.log(error, "e");
  }
);
//响应拦截器
service.interceptors.response.use(
  (config) => {
    const code = config.data["code"] || 200;
    if (code == 200) {
      return Promise.resolve(config.data);
    } else {
      // const msg = errorCodeType(code);
      // message.error(msg);
      message.error(config.data.msg);
      return Promise.reject(config.data);
    }
    // return config;
  },
  (error) => {
    console.log(error);
  }
);
export default service;
